<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.4.4.min.js"></script>
</head>
<body>

    <input type="button" value="Post请求" onclick="clickPost()">
    <input type="button" value="Put请求" onclick="clickPut()">
    <input type="button" value="Delete请求" onclick="clickDelete()">


</body>
<script type="text/javascript">
    function clickGet() {

        $.ajax({
            type:"GET",
            contentType: "application/json",
            url:"http://localhost:8080/user",
            success:function (data) {
                console.log(data)
            },
            error:function (data) {
                console.log("失败")
            }

        });
    }

    function clickPost() {

        var param={"id":1,"username":"郭旭东","sex":"男"}
        $.ajax({
            type:"POST",
            xhrFields: {
                // 跨域携带cookie
                withCredentials: true
            },
            data:JSON.stringify(param),
            contentType: "application/json",
            url:"http://localhost:8080/user",
            success:function (data) {
                alert(data);
            },
            error:function (data) {
                console.log("失败")
            }

        });
    }

    function clickDelete() {
        $.ajax({
            type:"delete",
            contentType: "application/json",
            url:"http://localhost:8080/user/1",
            success:function (data) {
                alert(data);
            },
            error:function (data) {
                console.log("失败")
            }

        });
    }

    function clickPut() {

        var param={"id":1,"username":"郭旭东","sex":"男"}
        $.ajax({
            type:"put",
            data:JSON.stringify(param),
            contentType: "application/json",
            url:"http://localhost:8080/user",
            success:function (data) {
                alert(data);
            },
            error:function (data) {
                console.log("失败")
            }

        });
    }
</script>
</html>